#!/bin/bash
echo '* Init home dir for a ftp user *'
echo '> Enter ftp username:'
read ftp_user

echo 'Init home dir for *' $ftp_user '*(Y|n)?'
read input_confirm 

if [ "$input_confirm"x != "Y"x ]; then
  exit 0
fi

user_home=/home/www/html/$ftp_user/
mkdir $user_home/www -p
touch $user_home/please_upload_to_www
chmod u-w $user_home 
chown -R www:www $user_home 

echo ''
echo '> Compeleted!' $user_home
ls -l $user_home
echo '' 

#create if user not exists
egrep "^$ftp_user" /etc/passwd >& /dev/null
if [ $? -ne 0 ];then
  useradd $ftp_user
  chsh $ftp_user -s /bin/false
  echo '> Set passwd for' $ftp_user ':'
  passwd $ftp_user
fi
